package dmt16.TelemetrySuit.UI.Tiles
{
	import dmt16.TelemetrySuit.Controller.SensorTypes.ISensorType;
	import dmt16.TelemetrySuit.UI.Colours;
	import dmt16.TelemetrySuit.UI.PlotTools.GraphLine;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	public class TileBase extends Sprite
	{	
		private var _tileContent:DisplayObject;
		private var _detailContent:DisplayObject;
					
		public static const WIDTH:Number=250;
		public static const HEIGHT:Number=250;
		
		public var hasControl:Boolean=false;
		
		public function TileBase(sensor:ISensorType=null)
		{
			_sensor=sensor;
			addEventListener(Event.ENTER_FRAME,_redraw);
			_tileContent=new Sprite();
			_detailContent=new Sprite();
			addChild(_tileContent);
			addEventListener(MouseEvent.CLICK,_onClick);
		}
		
		internal var _sensor:ISensorType;
		public function get sensor():ISensorType
		{
			return _sensor;
		}
		
		public static const FG_COLOUR:uint=Colours.FG;
		public static const BG_COLOUR:uint=Colours.BG;
		
		private function _redraw(event:Event):void{			
			graphics.clear();
			graphics.beginFill(BG_COLOUR);
			graphics.lineStyle(1,FG_COLOUR);
			graphics.drawRect(0,0,WIDTH,HEIGHT);
			
			_tileContent.x=0;
			_tileContent.y=0;
		}
		
		private function _onClick(event:MouseEvent):void{
			var evt:TileEvent=new TileEvent(TileEvent.TILE_SELECT,this);
			dispatchEvent(evt);
		}
		
		public function drawDetailContent():void{
			
		}
		
		public function get tileContent():DisplayObject{
			return _tileContent;
		}
		public function set tileContent(obj:DisplayObject):void{
			removeChild(_tileContent);
			addChild(obj);
			_tileContent=obj;
			_tileContent.x=0;
			_tileContent.y=0;
		}
		
		public function get detailContent():DisplayObject{
			return _detailContent;
		}
		public function set detailContent(obj:DisplayObject):void{
			_detailContent=obj;
		}
				
		public function get title():String{
			return "";
		}
	}
}